package com.anolesoft.twelvePlan.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.anolesoft.twelvePlan.dto.MesPlanXiadaJixingDTO;
import com.anolesoft.twelvePlan.entity.MesPlanXiadaJixingDO;
import com.anolesoft.twelvePlan.mapper.MesPlanXiadaJixingMapper;
import com.anolesoft.twelvePlan.service.MesPlanXiadaJixingService;
import com.anolesoft.yr.util.CommonUtils;
import com.anolesoft.yr.util.PageData;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author zyq
 * @date 2022/6/17
 */
@Service
@Slf4j
public class MesPlanXiadaJixingServiceImpl implements MesPlanXiadaJixingService {

    @Autowired
    private MesPlanXiadaJixingMapper mesPlanXiadaJixingMapper;

    @Override
    public PageData<List<MesPlanXiadaJixingDTO>> queryJX(MesPlanXiadaJixingDTO mesPlanXiadaJixingDTO, Integer pageNo, Integer pageSize) {
        Page<MesPlanXiadaJixingDO> page = new Page<>(pageNo, pageSize);
        List<MesPlanXiadaJixingDO> mesPlanXiadaJixingDOS = this.mesPlanXiadaJixingMapper.queryJX(MesPlanXiadaJixingDO.builder()
                .jixing(CommonUtils.stringNull(mesPlanXiadaJixingDTO.getJixing()))
                .factoryId(CommonUtils.stringNull(mesPlanXiadaJixingDTO.getFactoryId()))
                .createTime(mesPlanXiadaJixingDTO.getCreateTime())
                .nianyue(CommonUtils.stringNull(mesPlanXiadaJixingDTO.getNianyue()))
                .build(),page);
        List<MesPlanXiadaJixingDTO> mesPlanXiadaJixingDTOS = mesPlanXiadaJixingDOS.stream()
                .map(t -> BeanUtil.copyProperties(t, MesPlanXiadaJixingDTO.class))
                .collect(Collectors.toList());
        return new PageData<>(((int) page.getTotal()), mesPlanXiadaJixingDTOS);
    }
}
